package com.mijie.homi.dao.topic;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.mijie.core.IBatisDao;
import com.mijie.homi.domain.topic.ConsensusUser;
import com.mijie.homi.domain.topic.TopicOptions;

@Repository
@Transactional
public class TopicOptionsDao extends IBatisDao{

	public int settingOptions(List<TopicOptions> list){
		return this.insert("settingOptions", list);
	}
	
	public Integer getTopicIdByOptionId(int id){
		return this.selectInteger("getTopicIdByOptionId", id);
	}
	
	public List<TopicOptions> getOptions(int topicId){
		return this.selectList("getOptions", topicId);
	}
	
	public boolean alreadyChoice(int userId,int topicId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId", userId);
		parameter.put("topicId", topicId);
		Integer uid = this.selectInteger("alreadyChoice", parameter);
		return uid!=null && uid.equals(userId);
	}
	
	/*public int choiceOption(int userId,int topicId,int optionId){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("userId", userId);
		parameter.put("topicId", topicId);
		parameter.put("optionId", optionId);
		parameter.put("createAt", new Date());
		return this.insert("choiceOption", parameter);
	}*/
	
	public List<ConsensusUser> listConsensusUser(Map<String,Object> parameter){
		return this.selectList("listConsensusUser", parameter);
	}
	
	public int countConsensusUser(Map<String,Object> parameter){
		return this.selectInteger("countConsensusUser", parameter);
	}
	
	public int incrOptionNumOfChoices(int id){
		return this.insert("incrOptionNumOfChoices", id);
	}
	
	public int deleteOptionByTopicId(int topicId){
		return this.delete("deleteOptionByTopicId", topicId);
	}
	
}
